class Config(object):
    """配置参数"""
    # sqlalchemy的配置参数
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:root@127.0.0.1:3306/zhiyin"

    # 设置每次请求结束后会自动提交数据库中的改动，一般都设置手动保存
    SQLALCHEMY_COMMIT_ON_TEARDOWN = False

    # 设置sqlalchemy自动更新跟踪数据库
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    DEBUG = True







# import json
#
# from httpx import get
# from lxml import etree
#
# from mydb import session
# from sqlalchemy import text
#
# headers = {
#     'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
#     'accept-encoding': 'gzip, deflate, br',
#     'accept-language': 'zh-CN,zh;q=0.9',
#     'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Google Chrome";v="110"',
#     'sec-ch-ua-mobile': '?0',
#     'sec-ch-ua-platform': '"macOS"',
#     'sec-fetch-dest': 'document',
#     'sec-fetch-mode': 'navigate',
#     'sec-fetch-site': 'none',
#     'sec-fetch-user': '?1',
#     'upgrade-insecure-requests': '1',
#     'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'}
#
#
# def get_index_video_to_db():
#     ret = get('https://www.bilibili.com/', headers=headers)
#     html = etree.HTML(ret.text)
#     a_list = html.xpath('//*[@id="i_cecream"]/div[2]/main/div[2]/div/div[1]/div/div/div[2]/div/div/h3/a')
#     for a in a_list:
#         session.execute(text(f"insert into mp4(name, bl_url) VALUES ('{a.text}', '{a.get('href')}/')"))
#     session.commit()
#
#
# def get_audio_video_url2db(url):
#     ret = get(url, headers=headers)
#     html = etree.HTML(ret.text)
#     scrip = html.xpath('/html/head/script')
#     for i in scrip:
#         if i.text and i.text.startswith('window.__playinfo__'):
#             str_data = i.text.lstrip('window.__playinfo__=')
#             data = json.loads(str_data)
#             video_url = data['data']['dash']['video'][0]['baseUrl']
#             audio_url = data['data']['dash']['audio'][0]['baseUrl']
#             session.execute(
#                 text(f"UPDATE mp4 SET video = '{video_url}', audio = '{audio_url}' where bl_url='{url}'"))
#             session.commit()
#             return
#
#
# if __name__ == '__main__':
#     ...
#     # get_index_video()
#     get_audio_video_url2db('https://www.bilibili.com/video/BV1Fs4y1S76M/')






# from sqlalchemy import create_engine, Column, Integer, String
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy.ext.declarative import declarative_base
#
# # 创建对象的基类:
# Base = declarative_base()
#
# # 初始化数据库连接
# # 当前只是“试探”一下mysql 并没有真正连接
# engine = create_engine('mysql+pymysql://root:123456@localhost:3306/blbl')
# # 绑定session
# session = sessionmaker(bind=engine)
# session = session()